﻿ <!--Copyright (c) 2014, Dijji, and released under BSD, as defined by the text in the root of this distribution.-->
 <Window x:Class="Johnson.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:j="clr-namespace:Johnson"
        Title="{Binding Path=Title}" Height="600" Width="800" Loaded="Window_Loaded">
    <Window.Resources>
        <!--Used in TreeView-->
        <HierarchicalDataTemplate DataType="{x:Type j:Definition}" ItemsSource="{Binding Path=Quotes}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Content="defn"/>
                <TextBox Grid.Column="1" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" 
                         AcceptsReturn="True" MinWidth="60" GotFocus="TreeViewTextGotFocus" MaxWidth="{Binding Path=TreeViewItemWidth}" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                    <TextBox.InputBindings>
                        <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                    </TextBox.InputBindings>
                </TextBox>
            </Grid>
        </HierarchicalDataTemplate>

        <!--Used in TreeView -->
        <DataTemplate DataType="{x:Type j:Quote}" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Row="0" Grid.Column="0" Content="quote"/>
                <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" 
                         AcceptsReturn="True" MinWidth="60" MaxWidth="{Binding Path=TreeViewItemWidth}" GotFocus="TreeViewTextGotFocus" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                    <TextBox.InputBindings>
                        <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                    </TextBox.InputBindings>
                </TextBox>
                <Label Grid.Row="1" Grid.Column="0" Content="source"/>
                <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Source, UpdateSourceTrigger=PropertyChanged}" MinWidth="40" 
                         GotFocus="TreeViewTextGotFocus" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus"/>
            </Grid>
        </DataTemplate>

        <!--Used in ListBox-->
        <DataTemplate DataType="{x:Type j:Definition}" x:Key="DefinitionTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Content="defn"/>
                <TextBox Grid.Column="1" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"
                         VerticalScrollBarVisibility="Auto" MinWidth="60" GotFocus="ListViewTextGotFocus" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                    <TextBox.InputBindings>
                        <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                    </TextBox.InputBindings>
                </TextBox>
            </Grid>
        </DataTemplate>

        <!--Used in ListBox-->
        <DataTemplate DataType="{x:Type j:Quote}"  x:Key="QuoteTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Row="0" Grid.Column="0" Content="quote"/>
                <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" 
                         AcceptsReturn="True" MinWidth="60" GotFocus="ListViewTextGotFocus" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                    <TextBox.InputBindings>
                        <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                    </TextBox.InputBindings>
                </TextBox>
                <Label Grid.Row="1" Grid.Column="0" Content="source"/>
                <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Source, UpdateSourceTrigger=PropertyChanged}" MinWidth="40" 
                         GotFocus="ListViewTextGotFocus" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus"/>
            </Grid>
        </DataTemplate>

        <!--Keep the tree fully expanded by default-->
        <Style TargetType="TreeViewItem">
            <Setter Property="IsExpanded" Value="True" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
        </Style>

        <!--Stretch ListBox items to the full width of the ListBox-->
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
        </Style>

        <j:EnumMatchToBooleanConverter x:Key="enumBoolConverter" />
        <j:EnumMatchToVisibilityConverter x:Key="enumVisibilityConverter" />

        <ContextMenu Opened="ContextMenuOpened" x:Key="TextBoxContextMenu" x:Shared="true">
            <MenuItem Header="Cut" Tag="Selection" Click="ClickCut" InputGestureText="Ctrl+X" />
            <MenuItem Header="Copy" Tag="Selection" Click="ClickCopy" InputGestureText="Ctrl+C"/>
            <MenuItem Header="Paste" Tag="Clipboard" Click="ClickPaste" InputGestureText="Ctrl+V"/>
            <Separator/>
            <MenuItem  Header="Italicise" Tag="Selection" Click="ClickItalicise" InputGestureText="Ctrl+I"/>
            <MenuItem  Header="Remove line breaks" Click="ClickRemoveBreaks"/>
            <MenuItem  Header="Insert Æ" Tag="Insert" Click="ClickAEUpper"/>
            <MenuItem  Header="Insert æ" Tag="Insert" Click="ClickAELower"/>
            <MenuItem  Header="Insert Œ" Tag="Insert" Click="ClickOEUpper"/>
            <MenuItem  Header="Insert œ" Tag="Insert" Click="ClickOELower"/>
            <MenuItem  Header="Insert №" Tag="Insert" Click="ClickNumber"/>
            <MenuItem  Header="Insert §" Tag="Insert" Click="ClickSection"/>
            <MenuItem  Header="Insert Space" Tag="Insert" Click="ClickSpace"/>
            <MenuItem  Header="Insert —" Tag="Insert" Click="ClickDash"/>
        </ContextMenu>

        <Style TargetType="TextBox">
            <Setter Property="ContextMenu" Value="{DynamicResource TextBoxContextMenu}"/>
            <Setter Property="FontSize" Value="{Binding Path=FontSize}"/>
        </Style>
        
    </Window.Resources>

    <Window.CommandBindings>
        <CommandBinding Command="j:Command.Italicise" Executed="ClickItalicise"></CommandBinding>
        <CommandBinding Command="j:Command.AEUpper" Executed="ClickAEUpper"></CommandBinding>
        <CommandBinding Command="j:Command.AELower" Executed="ClickAELower"></CommandBinding>
        <CommandBinding Command="j:Command.OEUpper" Executed="ClickOEUpper"></CommandBinding>
        <CommandBinding Command="j:Command.OELower" Executed="ClickOELower"></CommandBinding>
        <CommandBinding Command="j:Command.Number" Executed="ClickNumber"></CommandBinding>
        <CommandBinding Command="j:Command.Section" Executed="ClickSection"></CommandBinding>
        <CommandBinding Command="j:Command.Space" Executed="ClickSpace"></CommandBinding>
        <CommandBinding Command="j:Command.Dash" Executed="ClickDash"></CommandBinding>
        <CommandBinding Command="j:Command.GrowFont" Executed="ClickGrowFont"></CommandBinding>
        <CommandBinding Command="j:Command.ShrinkFont" Executed="ClickShrinkFont"></CommandBinding>
    </Window.CommandBindings>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <ToolBar KeyboardNavigation.TabNavigation="Local">
                    <Button Command="j:Command.Italicise" IsEnabled="{Binding Path=HaveSelection}" ToolTip="Italicise selection" Content="I" FontStyle="Italic" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.AEUpper" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert Æ" Content="Æ" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.AELower" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert æ" Content="æ" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.OEUpper" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert Œ" Content="Œ" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.OELower" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert œ" Content="œ" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.Number" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert №" Content="№" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.Section" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert §" Content="§" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.Space" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert Space" Content="sp" FontWeight="Bold" FontStyle="Italic" FontFamily="Times New Roman"/>
                    <Button Command="j:Command.Dash" IsEnabled="{Binding Path=CanInsert}" ToolTip="Insert —" Content="—" FontWeight="Bold" FontFamily="Times New Roman"/>
                    <ToggleButton Content="}" ToolTip="Use Brace for Definitions" FontWeight="Bold" FontFamily="Times New Roman" IsChecked="{Binding Path=DefinitionBrace}"/>
                    <Button Command="j:Command.GrowFont" ToolTip="Increase the font size" FontWeight="Bold" FontFamily="Times New Roman">
                        <Image Source="Resources\grow.png"/>
                    </Button>
                    <Button Command="j:Command.ShrinkFont"  ToolTip="Decrease the font size" FontWeight="Bold" FontFamily="Times New Roman">
                        <Image Source="Resources\shrink.png"/>
                    </Button>
                </ToolBar>
            </Grid>
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Content="preamble"/>
                        <TextBox Grid.Row="1" Text="{Binding Path=Preamble, UpdateSourceTrigger=PropertyChanged}"/>
                    </Grid>
                    <Grid Grid.Column="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0"  Content="headword"/>
                        <TextBox Grid.Row="1" Text="{Binding Path=Headword, UpdateSourceTrigger=PropertyChanged}"/>
                    </Grid>
                    <Grid Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Content="or"/>
                        <TextBox Grid.Row="1" Text="{Binding Path=Headword2, UpdateSourceTrigger=PropertyChanged}"/>
                    </Grid>
                    <Grid Grid.Column="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Content="or"/>
                        <TextBox Grid.Row="1" Text="{Binding Path=Headword3, UpdateSourceTrigger=PropertyChanged}"/>
                    </Grid>
                    <Grid Grid.Column="4">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Content="postamble"/>
                        <TextBox Grid.Row="1" Text="{Binding Path=Postamble, UpdateSourceTrigger=PropertyChanged}"/>
                    </Grid>
                    <Grid Grid.Column="5">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Content="grammar"/>
                        <ComboBox Grid.Row="1" SelectedValue="{Binding Path=Grammar}" SelectedValuePath="." ItemsSource="{Binding Path=GrammarValues}"/>
                    </Grid>
                </Grid>
            </ScrollViewer>
            <Grid Grid.Row="2" Margin="0,5,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="50"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Margin="25,0,0,0" Content="from"/>
                <TextBox Grid.Column="1" MinWidth="60" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True"
                         Text="{Binding Path=From, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                    <TextBox.InputBindings>
                        <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                    </TextBox.InputBindings>
                </TextBox>
            </Grid>
            <Grid Grid.Row="3" Margin="0,5,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="50"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <RadioButton Grid.Row="0" Content="Single definition + Quotes" 
                             IsChecked="{Binding Path=Style, Mode=TwoWay, Converter={StaticResource enumBoolConverter},
                                        ConverterParameter=Single}"/>
                    <RadioButton Grid.Row="1" Content="Numbered definitions + Common quotes" 
                             IsChecked="{Binding Path=Style, Mode=TwoWay, Converter={StaticResource enumBoolConverter},
                                        ConverterParameter=NumCommon}"/>
                    <RadioButton Grid.Row="2" Content="Numbered definitions, each with quotes"
                             IsChecked="{Binding Path=Style, Mode=TwoWay, Converter={StaticResource enumBoolConverter},
                                        ConverterParameter=NumEach}"/>
                </Grid>
                <Button Grid.Column="1" Click="RemoveAllDefinitionsNum_Click" Margin="0,5,0,0">
                    <TextBlock Text="Clear Defini-tions" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Remove all definitions"/>
                </Button>

            </Grid>
              <!--Single definition + Quotes-->
            <Grid Grid.Row="4" Name="gridSingle" Visibility="{Binding Path=Style, Mode=OneWay, Converter={StaticResource enumVisibilityConverter},
                                        ConverterParameter=Single}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Label Grid.Row="0" Content="definition"/>
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>
                    <TextBox Grid.Column="0" Text="{Binding Path=SingleDefinition, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"
                              AcceptsReturn="True" VerticalScrollBarVisibility="Auto" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                        <TextBox.InputBindings>
                            <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                        </TextBox.InputBindings>
                    </TextBox>
                 </Grid> 
                <Label Grid.Row="2" Content="quotes"/>
                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>
                    <!--Turning off the Horizontal scroll bar tells ListItems to size to fit the ListBox-->
                    <ListBox Grid.Column="0" Name="listQuoteSingle" ItemsSource="{Binding Path=GeneralQuotes}" 
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemTemplate="{StaticResource QuoteTemplate}"
                             KeyboardNavigation.TabNavigation="Local"/>
                    <StackPanel Grid.Column="1" Orientation="Vertical">
                        <Button Click="AddGeneralQuote_Click">
                            <TextBlock Text="Add Quote" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Add a new quotation"/>
                        </Button>
                        <Button Click="RemoveGeneralQuoteSingle_Click" Margin="0,5,0,0">
                            <TextBlock Text="Remove Quote" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Remove the selected quotation"/>
                        </Button>
                    </StackPanel>
                </Grid>
            </Grid>
            <!--Numbered definitions, Common quotes-->
            <Grid Grid.Row="4" Name="gridNumCommon" Visibility="{Binding Path=Style, Mode=OneWay, Converter={StaticResource enumVisibilityConverter},
                                        ConverterParameter=NumCommon}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Label Grid.Row="0" Content="definitions"/>
                <Grid Grid.Row="1" Name="gridListNumCommon">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>
                    <ListBox Grid.Column="0" Name="listDefinitionNumCommon" ItemsSource="{Binding Path=Definitions}"
                             ItemTemplate="{StaticResource DefinitionTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                             KeyboardNavigation.TabNavigation="Local"/>
                    <StackPanel Grid.Column="1" Orientation="Vertical">
                        <Button Click="AddDefinition_Click">
                            <TextBlock Text="Add Defini-tion" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Add a new definition"/>
                        </Button>
                        <Button Click="RemoveDefinitionNumCommon_Click" Margin="0,5,0,0">
                            <TextBlock Text="Remove Defini-tion" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Remove the selected definition"/>
                        </Button>
                    </StackPanel>
                </Grid>
                <Label Grid.Row="2" Content="quotes"/>
                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>
                    <ListBox Grid.Column="0" Name="listQuoteNumCommon" ItemsSource="{Binding Path=GeneralQuotes}"
                              ItemTemplate="{StaticResource QuoteTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                             KeyboardNavigation.TabNavigation="Local"/>
                    <StackPanel Grid.Column="1" Orientation="Vertical">
                        <Button Click="AddGeneralQuote_Click">
                            <TextBlock Text="Add Quote" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Add a new quotation"/>
                        </Button>
                        <Button Click="RemoveGeneralQuoteNumCommon_Click" Margin="0,5,0,0">
                            <TextBlock Text="Remove Quote" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Remove the selected quotation"/>
                        </Button>
                    </StackPanel>
                </Grid>
            </Grid>
            <!--Numbered definitions, each with quotes-->
            <Grid Grid.Row="4" Name="gridNumEach" Visibility="{Binding Path=Style, Mode=OneWay, Converter={StaticResource enumVisibilityConverter},
                                        ConverterParameter=NumEach}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="0" Margin="0,5,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="50"/>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0" Margin="18,0,0,0" Content="notes"/>
                        <TextBox Grid.Column="1" MinWidth="60" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True"
                             Text="{Binding Path=SingleDefinition, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                            <TextBox.InputBindings>
                                <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                            </TextBox.InputBindings>
                        </TextBox>
                    </Grid>
                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="50"/>
                        </Grid.ColumnDefinitions>
                        <j:ShiftTabTreeView Grid.Column="0" x:Name="treeDefinitionNumEach" SizeChanged="treeDefinitionNumEach_SizeChanged" KeyboardNavigation.TabNavigation="Local">
                            <TreeViewItem ItemsSource="{Binding Path=Definitions}" Header="definitions"/>
                        </j:ShiftTabTreeView>
                        <StackPanel Grid.Column="1" Orientation="Vertical">
                            <Button Click="AddDefinition_Click">
                                <TextBlock Text="Add Defini-tion" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Add a new definition"/>
                            </Button>
                            <Button Click="RemoveDefinitionNumEach_Click" Margin="0,5,0,0">
                                <TextBlock Text="Remove Defini-tion" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Remove the selected definition"/>
                            </Button>
                            <Button Click="AddQuoteNumEach_Click" Margin="0,20,0,0">
                                <TextBlock Text="Add Quote" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Add a new quotation to the selected definition"/>
                            </Button>
                            <Button Click="RemoveQuoteNumEach_Click" Margin="0,5,0,0">
                                <TextBlock Text="Remove Quote" TextWrapping="Wrap" TextAlignment="Center" ToolTip="Remove the selected quotation"/>
                            </Button>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Grid>
            <Grid Grid.Row="5" Margin="0,5,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="50"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Margin="5,0,0,0" Content="notes"/>
                <TextBox Grid.Column="1" MinWidth="60" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True"
                         Text="{Binding Path=EndNote, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="TextBox_SelectionChanged" LostFocus="TextBox_LostFocus">
                    <TextBox.InputBindings>
                        <KeyBinding Key="I" Modifiers="Control" Command="j:Command.Italicise"></KeyBinding>
                    </TextBox.InputBindings>
                </TextBox>
            </Grid>
            <Grid Grid.Row="6">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button Grid.Column="0" Content="Choose Folder" Margin="5,5,0,5" Click="ChooseFolder_Click" ToolTip="Choose a folder to put the definitions in"/>
                <Button Grid.Column="1" Content="Open" Margin="5,5,0,5" Click="Open_Click" IsEnabled="{Binding Path=HaveFileDir}" ToolTip="Open a definition saved as XML"/>
                <Button Grid.Column="2" Content="Save" Margin="5,5,0,5" Click="Save_Click" IsEnabled="{Binding Path=HaveFileDir}" ToolTip="Save a definition as XML"/>
                <Button Grid.Column="3" Content="Export" Margin="5,5,0,5" Click="Export_Click" IsEnabled="{Binding Path=HaveFileDir}" ToolTip="Export a definition as HTML text"/>
                <Button Grid.Column="4" Content="Copy" Margin="5,5,0,5" Click="Copy_Click" ToolTip="Copy a definition to the clipboard as HTML text"/>
                <Button Grid.Column="5" Content="New" Margin="5,5,0,5" Click="Clear_Click" ToolTip="Start a new definition"/>
            </Grid>
        </Grid>
        <WebBrowser Grid.Column="1" HorizontalAlignment="Stretch" Margin="5" Name="webBrowser1" VerticalAlignment="Stretch" LoadCompleted="webBrowser1_LoadCompleted" />
        <!-- Awesomium web control can be used instead
        <awe:WebControl Grid.Column="1"
            Name="webControl" 
            Margin="5"
            ProcessCreated="webControl_ProcessCreated" 
            DocumentReady="webControl_DocumentReady"/>-->
    </Grid>
</Window>
